package com.xiaobias.a06;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class MyConfig1 {

    private static final Logger logger = LoggerFactory.getLogger(MyConfig1.class);

    @Autowired
    public void setApplicationContext(ApplicationContext applicationContext) {
        logger.debug("注入 ApplicationContext");
    }

    @PostConstruct
    public void init() {
        logger.debug("初始化");
    }

    //  Java 配置类再添加了 bean 工厂后置处理器后，
    //            你会发现现用传统接口方式的注入和初始化仍然成功， 而 @Autowired 和 @PostConstruct 的注入和初始化失败
    @Bean
    public BeanFactoryPostProcessor processor() {
        return beanFactory -> logger.debug("执行processor");
    }
}
